library(gganimate)
library(ggplot2)
library(maps)
library(ggthemes)
library(scales)
library(doBy)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)

###############
###Outbreaks###
###############
##Collapse data
outbreak.col <- summaryBy(outbreak_event~Country, data=dis.dat, FUN=c("sum"))
names(outbreak.col) <- c("admin", "Outbreaks")
#Define list of states
asian.countries <- c(
  "China","Mongolia","Taiwan","North Korea","South Korea","Japan","India","Bhutan","Bangladesh","Myanmar",
  "Sri Lanka","Nepal","Thailand","Cambodia","Laos","Vietnam","Malaysia","Singapore","Brunei","Philippines",
  "Indonesia","East Timor"  
)

#Define world map
world <- ne_countries(scale = "medium", country = asian.countries, returnclass = "sf")
#Combine data
outbreak.world <- merge(world, outbreak.col, by.x="admin")
#Plot mpa
map.all.col <- ggplot(data = outbreak.world) + 
  geom_sf(aes(fill=Outbreaks)) +
  scale_fill_gradient(label=comma, low = "lightpink",high = "darkred",) +
  theme_void()

#Export plot
setwd("~/OneDrive - Indiana University/FromGoogle/DiseaseFood/")
jpeg("mapout.jpeg", width = 8, height = 6, units = 'in', res = 500)
map.all.col
dev.off()

##########
###Flus###
##########
##Collapse data
outbreak.colB <- summaryBy(flus_all~Country, data=dis.dat, FUN=c("sum"))
names(outbreak.colB) <- c("admin", "Flu outbreaks")
#Define list of countries
asian.countries <- c(
  "China","Mongolia","Taiwan","North Korea","South Korea","Japan","India","Bhutan","Bangladesh","Myanmar",
  "Sri Lanka","Nepal","Thailand","Cambodia","Laos","Vietnam","Malaysia","Singapore","Brunei","Philippines",
  "Indonesia","East Timor"  
)

#Define world map
world <- ne_countries(scale = "medium", country = asian.countries, returnclass = "sf")
#Merge data
outbreak.worldB <- merge(world, outbreak.colB, by.x="admin")
#Plot map
map.all.colB <- ggplot(data = outbreak.worldB) + 
  geom_sf(aes(fill=`Flu outbreaks`)) +
  scale_fill_gradient(label=comma, low = "lightpink",high = "darkred",) +
  theme_void()

#Explort map
setwd("~/OneDrive - Indiana University/FromGoogle/DiseaseFood/")
jpeg("flusout.jpeg", width = 8, height = 6, units = 'in', res = 500)
map.all.colB
dev.off()

############
###Cattle###
############
##Collapse data
outbreak.col2 <- summaryBy(cattle_meat_tonnes~Country, data=dis.dat, FUN=c("sum"))
names(outbreak.col2) <- c("admin", "Cattle meat (tonnes)")
#Define list of countries
asian.countries <- c(
  "China","Mongolia","Taiwan","North Korea","South Korea","Japan","India","Bhutan","Bangladesh","Myanmar",
  "Sri Lanka","Nepal","Thailand","Cambodia","Laos","Vietnam","Malaysia","Singapore","Brunei","Philippines",
  "Indonesia","East Timor"  
)

#Define world map
world <- ne_countries(scale = "medium", country = asian.countries, returnclass = "sf")
#Merge data
cattle.world <- merge(world, outbreak.col2, by.x="admin")
#Plot map
map.all.col2 <- ggplot(data = cattle.world) + 
  geom_sf(aes(fill=`Cattle meat (tonnes)`)) +
  scale_fill_gradient(label=comma, low = "lightblue",high = "darkblue") +
  theme_void()

#Export map
setwd("~/OneDrive - Indiana University/FromGoogle/DiseaseFood/")
jpeg("mapcat.jpeg", width = 8, height = 6, units = 'in', res = 500)
map.all.col2
dev.off()


#############
###Chicken###
#############
##Collapse data
outbreak.col3 <- summaryBy(chicken_meat_tonnes~Country, data=dis.dat, FUN=c("sum"))
names(outbreak.col3) <- c("admin", "Chicken meat (tonnes)")
#Define list of countries
asian.countries <- c(
  "China","Mongolia","Taiwan","North Korea","South Korea","Japan","India","Bhutan","Bangladesh","Myanmar",
  "Sri Lanka","Nepal","Thailand","Cambodia","Laos","Vietnam","Malaysia","Singapore","Brunei","Philippines",
  "Indonesia","East Timor"  
)

#Define world map
world <- ne_countries(scale = "medium", country = asian.countries, returnclass = "sf")
#Merge data
chicken.world <- merge(world, outbreak.col3, by.x="admin")
#Plot map
map.all.col3 <- ggplot(data = chicken.world) + 
  geom_sf(aes(fill=`Chicken meat (tonnes)`)) +
  scale_fill_gradient(label=comma, low = "lightgreen",high = "darkgreen") +
  theme_void()

#Export map
setwd("~/OneDrive - Indiana University/FromGoogle/DiseaseFood/")
jpeg("mapchick.jpeg", width = 8, height = 6, units = 'in', res = 500)
map.all.col3
dev.off()



##########
###Pigs###
##########
##Collapse data
outbreak.col4 <- summaryBy(pigs_meat_tonnes~Country, data=dis.dat, FUN=c("sum"))
names(outbreak.col4) <- c("admin", "Pork (tonnes)")
#Define list of countries
asian.countries <- c(
  "China","Mongolia","Taiwan","North Korea","South Korea","Japan","India","Bhutan","Bangladesh","Myanmar",
  "Sri Lanka","Nepal","Thailand","Cambodia","Laos","Vietnam","Malaysia","Singapore","Brunei","Philippines",
  "Indonesia","East Timor"  
)

#Define world map
world <- ne_countries(scale = "medium", country = asian.countries, returnclass = "sf")
#Merge data
pigs.world <- merge(world, outbreak.col4, by.x="admin")
#Plot map
map.all.col4 <- ggplot(data = pigs.world) + 
  geom_sf(aes(fill=`Pork (tonnes)`)) +
  scale_fill_gradient(label=comma, low = "#CCA37A",high = "#4F311C") +
  theme_void()

#Export map
setwd("~/OneDrive - Indiana University/FromGoogle/DiseaseFood/")
jpeg("mappigs.jpeg", width = 8, height = 6, units = 'in', res = 500)
map.all.col4
dev.off()



####################
###Fertilizer Use###
####################
##Collapse data
outbreak.col5 <- summaryBy(comb.np.use_tonnes~Country, data=dis.dat, FUN=c("sum"))
names(outbreak.col5) <- c("admin", "Fertilizer use (tonnes)")
#Define countries
asian.countries <- c(
  "China","Mongolia","Taiwan","North Korea","South Korea","Japan","India","Bhutan","Bangladesh","Myanmar",
  "Sri Lanka","Nepal","Thailand","Cambodia","Laos","Vietnam","Malaysia","Singapore","Brunei","Philippines",
  "Indonesia","East Timor"  
)

#Define world map
world <- ne_countries(scale = "medium", country = asian.countries, returnclass = "sf")
#Merge data
fert.world <- merge(world, outbreak.col5, by.x="admin")
#Plot map
map.all.col5 <- ggplot(data = fert.world) + 
  geom_sf(aes(fill=`Fertilizer use (tonnes)`)) +
  scale_fill_gradient(label=comma, low = "#9932CC",high = "#68228B") +
  theme_void()

#Export map
setwd("~/OneDrive - Indiana University/FromGoogle/DiseaseFood/")
jpeg("mapfert.jpeg", width = 8, height = 6, units = 'in', res = 500)
map.all.col5
dev.off()

